import { defineConfig, loadEnv } from 'vite';

const { resolve } = require('path');
import createVitePlugins from './vite/plugins';
import inject from '@rollup/plugin-inject';
import vueJsx from "@vitejs/plugin-vue-jsx";

// https://vitejs.dev/config/
export default ({ mode, command }) => {
  const env = loadEnv(mode, process.cwd());
  const { VITE_APP_BASE } = env;
  return defineConfig({
    base: VITE_APP_BASE,
    server: {
      port: 2888,
      proxy: {
        '/api': {
           target: 'http://localhost',
           // target: 'http://erp.agop.com.cn:9090',
          // target: 'http://10.78.104.168',
          //target: 'http://test3.javablade.com',
          changeOrigin: true,
          rewrite: path => path.replace(/^\/api/, ''),
        },
          '/ws': {
              //本地服务接口地址
              // target: 'http://192.168.50.105',
              // target: 'http://10.78.105.168',
              // target: 'http://192.168.50.182',
              target: 'http://localhost',
              changeOrigin: true,      //是否跨域
              //远程演示服务地址,可用于直接启动项目
              //target: 'https://saber.bladex.vip/api',
              ws: true,
              // pathRewrite: {
              //   // '^/issue/api': '/'
              //   '^/ws': '/ws'
              // }
          },
          '/res': {
              //本地服务接口地址
              target: 'http://localhost:802',
              changeOrigin:true,
              //远程演示服务地址,可用于直接启动项目
              pathRewrite: {
                  '^/res': '/res'
              }
          }
      },
    },
    resolve: {
      alias: {
        '~': resolve(__dirname, './'),
        '@': resolve(__dirname, './src'),
        components: resolve(__dirname, './src/components'),
        styles: resolve(__dirname, './src/styles'),
        utils: resolve(__dirname, './src/utils'),
        'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
        'static': resolve(__dirname, ''),
      },
    },
    plugins: [
        createVitePlugins(env, command === 'build'),
        vueJsx(),
        inject({
            $: "jquery",  // 这里会自动载入 node_modules 中的 jquery   jquery全局变量
            jQuery: "jquery",
            "windows.jQuery": "jquery"
        })
    ],
  });
};
